package com.iseastar.guojiang.team.adapter;

import android.app.Activity;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.iseastar.guojiang.model.CourierTeamMemberApplyListBean;
import com.shouhuobao.station.R;
import com.shouhuobao.take.utils.DateUtils;
import com.shouhuobao.take.weight.CircularImage;

import java.util.ArrayList;

import droid.frame.activity.base.BaseAdapterExt;
import droid.frame.utils.GlideUtil;
import droid.frame.utils.lang.Str;

/**
 * 队员申请列表
 * Created by lidandan on 2018/6/15.
 */
public class CourierTeamMemberApplyListAdapter extends BaseAdapterExt<CourierTeamMemberApplyListBean> {

    public CourierTeamMemberApplyListAdapter(ArrayList<CourierTeamMemberApplyListBean> items, Activity context) {
        super(items, context);
        setEmptyView(R.layout.courier_team_member_apply_empty);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (hasEmptyView()) {
            return super.getView(position, convertView, parent);
        }
        ViewHolder holder = null;
        if (convertView == null || convertView.getTag() == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.courier_team_member_apply_item, parent, false);
            holder.mCourierTitleImage = (CircularImage) convertView.findViewById(R.id.courier_title_image);
            holder.mCourierNameTV = (TextView) convertView.findViewById(R.id.courier_name_tv);
            holder.mJoinTimeTV = (TextView) convertView.findViewById(R.id.join_time_tv);
            holder.mCourierMessageTV = (TextView) convertView.findViewById(R.id.courier_message_tv);
            holder.mOrderQuantityTV = (TextView) convertView.findViewById(R.id.order_quantity_tv);
            holder.mAuditTatusTV = (TextView) convertView.findViewById(R.id.audit_status_tv);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        CourierTeamMemberApplyListBean item = getItem(position);
        GlideUtil.loadImage(context, item.getImagePath(), R.drawable.setting_head_hover_default, holder.mCourierTitleImage);
        if (Str.isEmpty(item.getName())) {
            holder.mCourierNameTV.setText(item.getNickName() + "（）");
        } else {
            holder.mCourierNameTV.setText(item.getNickName() + "（" + item.getName().substring(0, 1) + "师傅）");
        }
        holder.mJoinTimeTV.setText(DateUtils.getTimeYMDHMSFormat().format(item.getCreateTime()).split(" ")[0] + " 申请加入");
        holder.mCourierMessageTV.setText(item.getSex() + "，" + item.getProvinceName() + "人，" + item.getAge() + "岁   " + item.getScore() + "分");
        holder.mOrderQuantityTV.setText("累计完成" + item.getTaskCount() + "单，本月总收入" + item.getTaskProfit() + "元");
        //处理不同状态的点击事件
        if(item.getStatus() == 1){
            holder.mAuditTatusTV.setText("去处理");
            holder.mAuditTatusTV.setTextColor(Color.parseColor("#6783d8"));
        }else if(item.getStatus() == 2){
            holder.mAuditTatusTV.setText("已同意");
            holder.mAuditTatusTV.setTextColor(Color.parseColor("#999999"));
        }else if(item.getStatus() == 3||item.getStatus() == 4) {
            holder.mAuditTatusTV.setText("已拒绝");
            holder.mAuditTatusTV.setTextColor(Color.parseColor("#999999"));
        }

        return convertView;
    }

    class ViewHolder {
        private CircularImage mCourierTitleImage;
        private TextView mCourierNameTV;
        private TextView mJoinTimeTV;
        private TextView mCourierMessageTV;
        private TextView mOrderQuantityTV;
        private TextView mAuditTatusTV;

    }
}
